<template>
  <el-container>
    <el-header>
      <img :src="pic" width="50" height="50"/>
      <span style="float: right">
         <el-button>欢迎[{{initUserInfo}}]使用</el-button>
        <el-button @click="logOut" >注销</el-button>
      </span>
    </el-header>
    <el-container>
      <el-aside width="auto">
        <el-menu
                :default-openeds="myOpeneds"
                :collapse="getMyCollapse"
                default-active="2"
                class="el-menu-vertical-demo"
                @open="handleOpen"
                @close="handleClose"
                background-color="#545c64"
                text-color="#fff"
                active-text-color="#ffd04b"
                router
        >
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>导航一</span>
            </template>
            <el-menu-item-group>
              <template slot="title">分组一</template>
              <el-menu-item index="/userList">用户列表</el-menu-item>
              <el-menu-item index="1-2">选项2</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="分组2">
              <el-menu-item index="1-3">选项3</el-menu-item>
            </el-menu-item-group>
            <el-submenu index="1-4">
              <template slot="title">选项4</template>
              <el-menu-item index="/main"><i class="el-icon-goods"></i>商品列表</el-menu-item>
              <el-menu-item index="/addPro"><i class="el-icon-goods"></i>商品添加</el-menu-item>
            </el-submenu>
          </el-submenu>
          <el-menu-item index="2">
            <i class="el-icon-menu"></i>
            <span slot="title">导航二</span>
          </el-menu-item>
          <el-menu-item index="3" disabled>
            <i class="el-icon-document"></i>
            <span slot="title">导航三</span>
          </el-menu-item>
          <el-menu-item index="4">
            <i class="el-icon-setting"></i>
            <span slot="title">导航四</span>
          </el-menu-item>
        </el-menu>

      </el-aside>
      <el-container>
        <el-main>
          <router-view></router-view>
        </el-main>
        <el-footer>
          &copy;林大2021java实训
        </el-footer>
      </el-container>
    </el-container>
  </el-container>

</template>

<script>


  import { ElMessage } from 'element-plus';

export default {
  name: 'App',
  created() {
    console.log("####"+this.$store.state.myCollapse)
  },
  //计算属性会自动计算
  computed: {
    initUserInfo(){
      return this.$store.state.userInfo
    },
    getMyCollapse () {
      return this.$store.state.myCollapse
    }
  },
  components: {
  },
  data: function() {
    return {
      pic:require('./assets/logo.png'),
      multipleSelection:[],
      value:true,
      myOpeneds:['1','1-4'],
      myCollapse:false,
      visible: false,
    }
  },
  methods: {

    logOut(){
      window.sessionStorage.clear()
      this.$store.commit('initUserInfo')
      this.$router.push("/login")
      ElMessage.success({
        message: '登出成功。',
        type: 'success'
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(val);
    },
    onSubmit() {
      console.log('submit!');
      console.log(this.formInline);

    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
  .el-aside{
    padding: 20px;
  }
</style>
